package org.devf.fork.imsimulator.help;

import java.security.MessageDigest;

/**
 * Md5Util related
 *
 * @author wanghuafu
 * @since 1.0  2023/9/13 14:51
 */
public class Md5Util {

    public static String md5(String value) {
        if (value == null || value.trim().length() == 0)
            return "";
        MessageDigest md5;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(value.getBytes());
            StringBuilder result = new StringBuilder();
            for (byte b : bytes) {
                String temp = Integer.toHexString(b & 0xff);
                if (temp.length() == 1) {
                    temp = "0" + temp;
                }
                result.append(temp);
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return value;
        }
    }

}
